package com.sunshine.effctive.chapter02.item2;

/**
 * 当构造方法参数过多时使用 builder 模式，
 * 可引用 @Builder 实现
 *
 * @author WeiHong
 * @date 2019/11/21 9:00
 */
//@Data
//@Builder
public class People {
    private String name;
    private int age;
    private String address;
    private String phone;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public static final class Builder {
        private String name;
        private int age;
        private String address;
        private String phone;

        private Builder() {
        }

        People build() {
            return new People(this);
        }

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder age(int age) {
            this.age = age;
            return this;
        }

        public Builder address(String address) {
            this.address = address;
            return this;
        }

        public Builder phone(String phone) {
            this.phone = phone;
            return this;
        }
    }

    private People(Builder builder) {
        this.name = builder.name;
        this.age = builder.age;
        this.address = builder.address;
        this.phone = builder.phone;
    }

    public static Builder builder() {
        return new Builder();
    }
}
